
<link rel="stylesheet" th:href="@{/ui/css/amazeui.chosen.css}" />
<script th:src="@{/ui/js/amazeui.chosen.js}"></script>
<script th:src="@{/ui/js/region.js}"></script>



<div class="row-content am-cf">
	<div class="row">
		<div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
			<div class="widget am-cf">
				<div class="widget-head am-cf">
					<div class="widget-title am-fl">新增白名单合伙人</div>
					<div class="widget-function am-fr">
						<a href="javascript:;" class="am-icon-cog"></a>
					</div>
				</div>
				<div class="widget-body am-fr">
					<form class="am-form tpl-form-line-form" id="whiteForm" method="post">
						<input type="hidden" id="agentId" name="agentId" th:value="${agent.id}" />
						<input type="hidden" name="status" th:value="${agent.status}" />
						<input type="hidden" name="agentDetailId" th:value="${agentDetail.id}" />
						<input type="hidden" name="bankCardId" th:value="${agentBankCard != nul?agentBankCard.id:''}" />
						<input id="idcardUrl" type="hidden"   th:value="${agentDetail.idcardFront}"/>
						<div class="am-form-group">
							<label for="realName" class="am-u-sm-12 am-u-lg-2 am-form-label">合伙人姓名:</label>
							<div class="am-u-sm-12 am-u-lg-4">
								<input type="text" id="realName" class="tpl-form-input" placeholder="姓名" maxlength='30' name="realName"  th:value="${agent.realName}" required="required"/> 
							</div>
							<label for="mobile" class="am-u-sm-12 am-u-lg-2 am-form-label">手机号:</label>
							<div class="am-u-sm-12 am-u-lg-4">
								<input type="number" id="mobile" class="tpl-form-input" placeholder="手机号" name="mobile" th:value="${agent.mobile}" maxlength="11" required="required"/> 
							</div>
						</div>
						
						<div class="am-form-group">
							<label for="idcard" class="am-u-sm-12 am-u-lg-2 am-form-label">身份证:</label>
							<div class="am-u-sm-12 am-u-lg-4 am-u-end">
								<input type="text" id="idcard" class="tpl-form-input" placeholder="身份证" name="idcard"  maxlength='18' th:value="${agent.idcard}" required="required" /> 
							</div>
							<label for="successTime" class="am-u-sm-2 am-form-label">签约时间:</label>
							<div class="am-u-sm-2 am-u-end">
								<input type="text" placeholder="签约时间" id="signTime" name="signTime" th:value="${signTime}" class="form-datetime-lang am-form-field"/>
							</div>
						</div>
						<div class="am-form-group">
							<label for="descs" class="am-u-sm-2 am-form-label">上传身份证
							</label>
							<div class="am-u-sm-10">
								<input id="upFile" type="file"  />
								<input id="coverImg" type="hidden"   name="idcardFront" th:value="${idcardFront}"/>
							</div>
						</div>
						
						<div class="am-form-group">
							
							<label for="role" class="am-u-sm-2 am-form-label">搭档:</label>
							<div class="am-u-sm-4">
								<select id="isPartner" data-am-selected="{searchBox: 1}"  style="display: none;" name="isPartner" required="required" >
									<option th:each="partner : ${partners}" 	     th:value="${partner.key}"    th:text="${partner.value}" th:selected="${partner.key==agent.isPartner}" ></option>
								</select> 
							</div>
							
							<label for="partnerMobile" class="am-u-sm-2 am-form-label">搭档手机号:</label>
							<div class="am-u-sm-3">
								<input type="number" id="partnerMobile" class="tpl-form-input" placeholder="搭档手机号" name="partnerMobile" th:value="${agentPartner == null?'':agentPartner.mobile}" /> 
							</div>
							<span class="am-u-sm-1" id="partnerName" th:text="${agentPartner == null?'':agentPartner.realName}"></span>
						</div>
						
						<div class="am-form-group">
							
							<label for="role" class="am-u-sm-2 am-form-label">等级:</label>
							<div class="am-u-sm-4">
								<select id="grade" data-am-selected="{searchBox: 1}"  style="display: none;" name="grade" required="required" >
									<option th:each="grade : ${grades}" 	     th:value="${grade.key}"    th:text="${grade.value}" th:selected="${grade.key==agent.grade}" ></option>
								</select> 
							</div>
							<label for="cardNo" class="am-u-sm-2 am-form-label">上级合伙人手机号:</label>
							<div class="am-u-sm-3">
								<input type="number" id="parentMobile" class="tpl-form-input"  placeholder="上级合伙人手机号" name="parentMobile" th:value="${agentParent == null?'':agentParent.mobile}" /> 
							</div>
							<span class="am-u-sm-1" id="parentName" th:text="${agentParent == null?'':agentParent.realName}"></span>
						</div>
						<div class="am-form-group">
							<label for="qq" class="am-u-sm-2 am-form-label">目前或最后一个工作单位:</label>
							<div class="am-u-sm-4">
								<input type="text" id="latestWork" name="latestWork" th:value="${agentDetail.latestWork}"/>
							</div>
							<label for="qq" class="am-u-sm-2 am-form-label">职务:</label>
							<div class="am-u-sm-4">
								<input type="text" id="latestDuty" name="latestDuty" th:value="${agentDetail.latestDuty}"/>
							</div>
						</div>
						<div class="am-form-group">
							<label for="job" class="am-u-sm-12 am-u-lg-2 am-form-label">职业:</label>
							<div class="am-u-sm-12 am-u-lg-4">
								<select id="job" data-am-selected="{searchBox: 1}"  style="display: none;" name="job" required="required">
									<option th:each="job : ${jobs}"  th:value="${job.key}"    th:text="${job.value}" th:selected="${job.key==agentDetail.job}"></option>
								</select> 
							</div>
							<label for="qq" class="am-u-sm-2 am-form-label">曾任职主要行业或单位、职务:</label>
							<div class="am-u-sm-4">
								<input type="text" id="majorDuty" name="majorDuty" th:value="${agentDetail.majorDuty}"/>
							</div>
						</div>
						<div class="am-form-group">
							<label for="qq" class="am-u-sm-2 am-form-label">QQ:</label>
							<div class="am-u-sm-2">
								<input type="text" id="qq" name="qq" th:value="${agentDetail.qq}"/>
							</div>
							<label for="qq" class="am-u-sm-2 am-form-label">邮箱:</label>
							<div class="am-u-sm-2">
								<input type="text" id="email" name="email" th:value="${agentDetail.email}"/>
							</div>
							<label for="qq" class="am-u-sm-2 am-form-label">微信:</label>
							<div class="am-u-sm-2">
								<input type="text" id="wechat" name="wechat" th:value="${agentDetail.wechat}"/>
							</div>
						</div>
						<div class="am-form-group">
							<label for="address" class="am-u-sm-2 am-form-label">合伙人家庭住址:</label>
							<div class="am-u-sm-10">
								<input type="text" id="address" name="address" th:value="${agentDetail.address}" placeholder="请输入合伙人家庭住址"/>
							</div>
						</div>
						<hr/>
						<div class="am-form-group">
							<label for="region" class="am-u-sm-2 am-form-label"><h4>授权业务区域</h4></label>
						</div>	
						<div class="am-form-group">
							<label for="province" class="am-u-sm-2 am-form-label">管辖区域:</label>
					        <select id="provinceId" name="provinceId" data-placeholder="请选择省"   th:value="${agentDetail.provinceId}"  class="province" style="width:12%" tabindex="7" >
					            <option value=""></option>
					        </select>
					        <select data-placeholder="请选择市" class="city" id="cityId" name="cityId" style="width:12%" tabindex="7" th:value="${agentDetail.cityId}">
					            <option value=""></option>
					        </select>
   					    </div>
   					   	<div class="am-form-group" id="countyOutDiv">
   					  	 	<label  class="am-u-sm-2 am-form-label">县:</label>
   					  	 	<button type="button" onclick="addItemValue('county')" class="am-btn am-btn-success tpl-btn-bg-color-success am-btn-sm am-round">添加</button>
   					  	 	<button type="button" onclick="removeItemValue('county')"  class="am-btn am-btn-success tpl-btn-bg-color-success am-btn-sm am-round">删除</button>
	 					  	<div class="am-u-sm-10"  style="float:right">
	 					  	<input type="text" readonly="readonly" name="countyName"  id="countyName" placeholder="请点击添加按钮后选择" th:value="${agentDetail.countyName}" />
	 					  	<input type="hidden"  name="countyId"  id="countyId"   th:value="${agentDetail.countyId}" />
	 					  	<div style="visibility:hidden" id="countyDiv">
					        <select data-placeholder="请选择区/县" class="area"  name="countySel" id="countySel" >
					            <option value=""></option>
					        </select>
	 					  	</div>
	 					  	</div>
	 					</div>
   					   	<div class="am-form-group" id="townOutDiv">
   					  	 	<label  class="am-u-sm-2 am-form-label">镇:</label>
   					  	 	<button type="button" onclick="addItemValue('town')" class="am-btn am-btn-success tpl-btn-bg-color-success am-btn-sm am-round">添加</button>
   					  	 	<button type="button" onclick="removeItemValue('town')"  class="am-btn am-btn-success tpl-btn-bg-color-success am-btn-sm am-round">删除</button>
	 					  	<div class="am-u-sm-10"  style="float:right">
	 					  	<input type="text" readonly="readonly" name="townName"  id="townName" placeholder="请点击添加按钮后选择" th:value="${agentDetail.townName}" />
	 					  	<input type="hidden"  name="townId"  id="townId"   th:value="${agentDetail.townId}" />
	 					  	<div style="visibility:hidden" id="townDiv">
					        <select data-placeholder="请选择镇" class="town"  name="townSel" id="townSel" >
					            <option value=""></option>
					        </select>
	 					  	</div>
	 					  	</div>
	 					</div>
   					   	<div id="villageDiv" class="am-form-group">
   					  	 	<label for="village" class="am-u-sm-2 am-form-label">村:</label>
   					  	 	<button type="button" onclick="addItemEvent('villageOutDiv')" class="am-btn am-btn-success tpl-btn-bg-color-success am-btn-sm am-round">添加</button>
   					  	 	<button type="button" onclick="removeItemEvent('villageOutDiv')"  class="am-btn am-btn-success tpl-btn-bg-color-success am-btn-sm am-round">删除</button>
	 					  	<div th:each="village,idx : ${agentVillages}" >
								<div class="am-u-sm-10" name="villageOutDiv" style="float:right"><input type="text"  name="villageArr" placeholder="请输入管辖行政村" th:value="${village}" /></div>
	 					  	</div>
						</div>
						<hr/>
						<div class="am-form-group">
							<label for="region" class="am-u-sm-2 am-form-label"><h4>联系人信息</h4></label>
						</div>	
						<div class="am-form-group">
							<label for="relativeName" class="am-u-sm-2 am-form-label">姓名:</label>
							<div class="am-u-sm-4">
								<input type="text" id="relativeName" name="relativeName" th:value="${agentDetail.relativeName}" />
							</div>
							
							<label for="relativePhone" class="am-u-sm-2 am-form-label">手机号:</label>
							<div class="am-u-sm-4">
								<input type="text" id="relativePhone" name="relativePhone" th:value="${agentDetail.relativePhone}"/>
							</div>
						</div>
						
						
						<div class="am-form-group">
							<label for="workplace" class="am-u-sm-2 am-form-label">工作单位:</label>
							<div class="am-u-sm-4">
								<input type="text" id="desc" name="workplace" placeholder="请输入工作单位" th:value="${agentDetail.workplace}" />
							</div>
							<label for="workplace" class="am-u-sm-2 am-form-label">关系:</label>
							<div class="am-u-sm-4">
									<select id="relationType" th:name="relationType">
										<option th:each="job : ${relationType}"  th:value="${job.key}"    th:text="${job.value}" th:selected="${job.key==agentDetail.relationType}"></option>
									</select> 	
							</div>
						</div>
						
						<hr/>
						<div class="am-form-group">
							<label for="region" class="am-u-sm-2 am-form-label"><h4>银行卡信息</h4></label>
						</div>			
						<div class="am-form-group">
							<label for="bankId" class="am-u-sm-2 am-form-label">合伙人银行:</label>
							<div class="am-u-sm-4">
								<select id="bankId"  data-am-selected="{btnWidth: '40%', btnSize: 'sm'}" name="bankId"  >
									<option value="">请选择银行</option>
									<option th:each="bank : ${banks}" 	     th:value="${bank.id}"    th:text="${bank.name}" th:selected="${bank.id== (agentBankCard != nul?agentBankCard.bankId:'')}"></option>
								</select> 
							</div>
							
							<label for="cardno" class="am-u-sm-2 am-form-label">合伙人银行卡号:</label>
							<div class="am-u-sm-4">
								<input type="number" id="cardno" class="tpl-form-input" placeholder="合伙人银行" name="cardno" th:value="${agentBankCard != null?agentBankCard.cardno:''}" /> 
							</div>
						</div>
						<div class="am-form-group">
							<div>							
								<label for="region" class="am-u-sm-2 am-form-label">银行卡支行:</label>
								<div class="am-u-sm-4  am-u-end">
									<input type="text" id="branch" class="tpl-form-input" placeholder="支行信息" name="branch" th:value="${agentBankCard != null?agentBankCard.branch:''}" /> 
								</div>
							</div>
						</div>
						
						<hr/> 
						<div class="am-form-group">
							<label for="region" class="am-u-sm-2 am-form-label"><h4>房产</h4></label>
							<button type="button" onclick="addItemEvent('house')" class="am-btn am-btn-success tpl-btn-bg-color-success am-btn-sm am-round">添加</button>
							<button type="button" onclick="removeItemEvent('house')"  class="am-btn am-btn-success tpl-btn-bg-color-success am-btn-sm am-round">删除</button>
						</div>
						<th:block th:each="houseItem,index1 : ${house}">
							<div class="am-form-group" name="house">
								  <div>
										<div class="am-form-group ">
											<input type="hidden" th:id="|house[${index1.index}].id|" th:name="|house[${index1.index}].id|" th:value="${houseItem.id}" />
											<label for="region" class="am-u-sm-2 am-form-label">房产类型:</label>
											<div class="am-u-sm-2 ">
												<select th:id="|house[${index1.index}].type|" th:name="|house[${index1.index}].type|">
													<option th:each="job : ${houseType}"  th:value="${job.key}"    th:text="${job.value}" th:selected="${job.key==houseItem.type}"></option>
												</select> 							
											</div>
											<label for="region" class="am-u-sm-2 am-form-label">房产面积(㎡):</label>
											<div class="am-u-sm-2  ">
												<input type="text" th:id="|house[${index1.index}].area|" class="tpl-form-input"  th:name="|house[${index1.index}].area|" th:value="${houseItem.area}" /> 
											</div>
											<label for="region" class="am-u-sm-2 am-form-label">扣除本息后余值（万）:</label>
											<div class="am-u-sm-2  am-u-end">
												<input type="number" th:id="|house[${index1.index}].money|" class="tpl-form-input"  th:name="|house[${index1.index}].money|" th:value="${houseItem.money}" /> 
											</div>
										</div>
										<div class="am-form-group">							
											<label for="region" class="am-u-sm-2 am-form-label">购买/自建年份:</label>
											<div class="am-u-sm-2">
													<input type="number" th:id="|house[${index1.index}].fromYear|" class="tpl-form-input" th:name="|house[${index1.index}].fromYear|" th:value="${houseItem.fromYear}" /> 
											</div>
											<label for="region" class="am-u-sm-2 am-form-label">详细地址:</label>
											<div class="am-u-sm-4  am-u-end">
												<input type="text" th:id="|house[${index1.index}].address|" class="tpl-form-input"  th:name="|house[${index1.index}].address|" th:value="${houseItem.address}" /> 
											</div>
										</div>
								</div>
							</div>
						</th:block>
						
						<hr/>
						<div class="am-form-group">
							<label for="region" class="am-u-sm-2 am-form-label"><h4>车产</h4></label>
							<button type="button" onclick="addItemEvent('car')" class="am-btn am-btn-success tpl-btn-bg-color-success am-btn-sm am-round">添加</button>
							<button type="button" onclick="removeItemEvent('car')"  class="am-btn am-btn-success tpl-btn-bg-color-success am-btn-sm am-round">删除</button>
						</div>
						<th:block th:each="carItem,index1 : ${car}">
							<div class="am-form-group" name="car">
								  <div>
										<div class="am-form-group ">
											<input type="hidden" th:id="|car[${index1.index}].id|" th:name="|car[${index1.index}].id|" th:value="${carItem.id}" />
											<label for="region" class="am-u-sm-2 am-form-label">车产类型:</label>
											<div class="am-u-sm-2 ">
												<select th:id="|car[${index1.index}].type|" th:name="|car[${index1.index}].type|">
													<option th:each="job : ${carType}"  th:value="${job.key}"    th:text="${job.value}" th:selected="${job.key==carItem.type}"></option>
												</select> 							
											</div>
											<label for="region" class="am-u-sm-2 am-form-label">扣除贷款本息后余值（万）:</label>
											<div class="am-u-sm-2 ">
												<input type="number" th:id="|car[${index1.index}].money|" class="tpl-form-input"  th:name="|car[${index1.index}].money|" th:value="${carItem.money}" /> 
											</div>
											<label for="region" class="am-u-sm-2 am-form-label">购买年份:</label>
											<div class="am-u-sm-2  am-u-end">
													<input type="number" th:id="|car[${index1.index}].fromYear|" class="tpl-form-input" th:name="|car[${index1.index}].fromYear|" th:value="${carItem.fromYear}" /> 
											</div>
										</div>
								</div>
							</div>
						</th:block>
						
						<hr/> 		
						<div class="am-form-group">
							<label for="region" class="am-u-sm-2 am-form-label"><h4>个人/家庭投资情况</h4></label>
							<button type="button" onclick="addItemEvent('invest')" class="am-btn am-btn-success tpl-btn-bg-color-success am-btn-sm am-round">添加</button>
							<button type="button" onclick="removeItemEvent('invest')"  class="am-btn am-btn-success tpl-btn-bg-color-success am-btn-sm am-round">删除</button>
						</div>
						<th:block th:each="investItem,index1 : ${invest}">
							<div class="am-form-group" name="invest">
								  <div>
										<div class="am-form-group ">
											<input type="hidden" th:id="|invest[${index1.index}].id|" th:name="|invest[${index1.index}].id|" th:value="${investItem.id}" />
											<label for="region" class="am-u-sm-2 am-form-label">投资类型:</label>
											<div class="am-u-sm-2 ">
												<input type="number" th:id="|invest[${index1.index}].type|" class="tpl-form-input"  th:name="|invest[${index1.index}].type|" th:value="${investItem.type}" /> 
											</div>
											<label for="region" class="am-u-sm-2 am-form-label">投资现值（万）:</label>
											<div class="am-u-sm-2 am-u-end">
												<input type="number" th:id="|invest[${index1.index}].money|" class="tpl-form-input"  th:name="|invest[${index1.index}].money|" th:value="${investItem.money}" /> 
											</div>
										</div>
								</div>
							</div>
						</th:block>
						<hr/> 
						<div class="am-form-group">
							<label for="region" class="am-u-sm-2 am-form-label"><h4>个人/家庭负债情况</h4></label>
							<button type="button" onclick="addItemEvent('debt')" class="am-btn am-btn-success tpl-btn-bg-color-success am-btn-sm am-round">添加</button>
							<button type="button" onclick="removeItemEvent('debt')"  class="am-btn am-btn-success tpl-btn-bg-color-success am-btn-sm am-round">删除</button>
						</div>
						<th:block th:each="debtItem,index1 : ${debt}">
							<div class="am-form-group" name="debt">
								  <div>
										<div class="am-form-group ">
											<input type="hidden" th:id="|debt[${index1.index}].id|" th:name="|debt[${index1.index}].id|" th:value="${debtItem.id}" />
											<label for="region" class="am-u-sm-2 am-form-label">银行贷款余额（万）:</label>
											<div class="am-u-sm-2 ">
												<input type="number" th:id="|debt[${index1.index}].moneyBank|" class="tpl-form-input"  th:name="|debt[${index1.index}].moneyBank|" th:value="${debtItem.moneyBank}" /> 
											</div>
											<label for="region" class="am-u-sm-2 am-form-label">其他借款余额（万）:</label>
											<div class="am-u-sm-2 am-u-end">
												<input type="number" th:id="|debt[${index1.index}].moneyOther|" class="tpl-form-input"  th:name="|debt[${index1.index}].moneyOther|" th:value="${debtItem.moneyOther}" /> 
											</div>
										</div>
								</div>
							</div>
						</th:block>
						
						<hr/> 
						<div class="am-form-group">
							<div class="am-u-sm-10 am-u-sm-push-2">
								
								<button type="button" onclick="javascript:$('#whiteForm').submit();"
									class="am-btn am-btn-primary tpl-btn-bg-color-success ">提交</button>
								<button type="button" th:onclick="'javascript:loadPage(\''+${backUrl}+'\')'"
									class="am-btn am-btn-success tpl-btn-bg-color-success ">返回</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>

	</div>
	<script th:inline="javascript">
	<![CDATA[
		
	var checkParentMobile = true,checkPartnerMobile=true;
	
	var canSubmit = true;//表单重复提交控制 
	
	$(document).ready(function(){
		$('#job,#grade,#bankId,#isPartner,.mySelect').selected();
		
		var initImg = "<img src='" + $('#idcardUrl').val() + "' class='file-preview-image'>";
		initUpFileOne('upFile','coverImg','选择图片',initImg);
		
		if($("#agentId").val()){
			$("#grade,#isPartner").selected('disable');
			if($("#grade").val() == "14"){
				$("#parentMobile").hide();//县级代理没上级
			}
			dealPartnerSet();
		}
		
		$('#signTime').datetimepicker({
			format: 'yyyy-mm-dd hh:ii:ss',
			autoclose: true,
	        todayBtn: true,
			language:  'zh-CN'
		});
		
		if($("#grade").val() == "14"){
			$("#cityId_chosen").hide();
			$("#countyOutDiv").hide();
			$("#townOutDiv").hide();
			$("#villageDiv").hide();
		}
		if($("#grade").val() == "13"){
			$("#countyOutDiv").hide();
			$("#townOutDiv").hide();
			$("#villageDiv").hide();
		}
		if($("#grade").val() == "12"){
			$("#townOutDiv").hide();
			$("#villageDiv").hide();
		}	
		if($("#grade").val() == "11"){
			$("#villageDiv").hide();
		}
		
		$("#job").on("change",function(){
			$("#job").valid();
		});
		
		$("#isPartner").on("change",function(){
			dealPartnerSet();
		});
		
		$("#grade").on("change",function(){
			if($(this).val() == "14"){
				$(".town").val("").trigger('chosen:updated').hide();
				$("#cityId_chosen").hide();
				$("#countyOutDiv").hide();
				$("#townOutDiv").hide();
				$("#villageDiv").hide();
				$("input[name='villageArr']").val("");
				$("#parentMobile").hide();//省级代理无上级
			}
			else if($(this).val() == "13"){
				$(".town").val("").trigger('chosen:updated').hide();
				$("#countyOutDiv").hide();
				$("#townOutDiv").hide();
				$("#villageDiv").hide();
				$("input[name='villageArr']").val("");
				$("#cityId_chosen").show();
				$("#parentMobile").show();
			}
			else if($(this).val() == "12"){//县级
				$(".town").val("").trigger('chosen:updated').hide();
				$("#townOutDiv").hide();
				$("#villageDiv").hide();
				$("input[name='villageArr']").val("");
				$("#cityId_chosen").show();
				$("#countyOutDiv").show();
				$("#parentMobile").show();
			}else if($(this).val() == "11"){
				$("#villageDiv").hide();
				$("input[name='villageArr']").val("");
				$("#cityId_chosen").show();
				$("#countyOutDiv").show();
				$("#townOutDiv").show();
				$("#parentMobile").show();
			}else if($(this).val() == "10"){
				$("#cityId_chosen").show();
				$("#countyOutDiv").show();
				$("#townOutDiv").show();
				$("#villageDiv").show();
				$("#parentMobile").show();
			}
			dealPartnerSet();
			$("#grade").valid();
		});
		
		
		$("#parentMobile").on("mouseleave",function(){
			  var parentMobile = $("#parentMobile").val();
			  if(parentMobile == ""){
				  checkParentMobile = true;
				  return;
			  }
			  checkParentMobile = false;
		      $.ajax({
		            type : "GET",
		            url :  "agentManage/"+parentMobile+"/agent",
		            dataType : "json",
		            success : function(resultdata) {
		                if (resultdata.ret=="200") {
		                	if(resultdata.content.code == "10000"){
		                		checkParentMobile = true;
		                		$("#parentName").text(resultdata.content.info.realName);
		                	}else{
		                		checkParentMobile = false;
		                		$("#parentName").html('<font color="red">'+resultdata.content.msg+'</font>');
		                	}
		                } else {
		                    layer.msg(resultdata.message, {
		                        icon : 0
		                    });
		                }
		            },
		            error : function(errorMsg) {
		                layer.msg('服务器未响应,请稍后再试', {
		                    icon : 3
		                });
		            }
		        });
		});
		
		$("#partnerMobile").on("mouseleave",function(){
			  var parentMobile = $("#partnerMobile").val();
			  if(parentMobile == ""){
				  checkPartnerMobile = true;
				  return;
			  }
			  checkPartnerMobile = false;
		      $.ajax({
		            type : "GET",
		            url :  "agentManage/"+parentMobile+"/agent",
		            dataType : "json",
		            success : function(resultdata) {
		                if (resultdata.ret=="200") {
		                	if(resultdata.content.code == "10000"){
		                		checkPartnerMobile = true;
		                		$("#partnerName").text(resultdata.content.info.realName);
		                	}else{
		                		checkPartnerMobile = false;
		                		$("#partnerName").html('<font color="red">'+resultdata.content.msg+'</font>');
		                	}
		                } else {
		                    layer.msg(resultdata.message, {
		                        icon : 0
		                    });
		                }
		            },
		            error : function(errorMsg) {
		                layer.msg('服务器未响应,请稍后再试', {
		                    icon : 3
		                });
		            }
		        });
		});
	
	});

	validateUserForm();
	function validateUserForm(){    
	    $('#whiteForm').validate({
	        errorElement : 'span',
	        errorClass : 'am-icon-times',
	        focusInvalid : true,
	        onkeyup:false,
	        onfocusout: false,
	        ignore : "",
	        rules : {
	            mobile : {
	                required : true,
	                maxlength: 11
	            }
	            
	        },
	        messages : {
	        	
	        },
	        submitHandler : function(form) {
	        	if(checkParentMobile && checkPartnerMobile){
	        		if(canSubmit){
	        			commit('whiteForm', 'agentwhite/save','agentwhite/whiteList');
	        		}
	        		
	        	}
	        }
	    });
	}
	
	function addItemEvent(name){
		var $baseDiv = $("div[name="+name+"]");
		var size = $baseDiv.length;
		var html = $baseDiv.eq(0).prop("outerHTML");
		var newStr = "["+size+"]";
		html = html.replace(/\[0\]/g,newStr);
		$baseDiv.eq(size-1).after(html);
		$("[id^='"+name+"\\["+size+"\\]']").val("");
	}
	
	function removeItemEvent(name){
		var $baseDiv = $("div[name="+name+"]");
		var size = $baseDiv.length;
		if(size>1){
			$baseDiv[size-1].remove();	
		}
	}
	
	function dealPartnerSet(){
		if($("#isPartner").val() == '0'){//非合伙人
			$("#partnerMobile").hide();
			//$("#parentMobile").show();
		}else if($("#isPartner").val() == '1'){
			$("#partnerMobile").show();
			//$("#parentMobile").val("").hide();//合伙人没上级
			$("#parentName").text("");
		}
	}

	function initUpFileOne(id,showId,label,initImg){
		$('#'+id+'').fileinput({
			 showUpload : true,
		     showRemove : false,
		     showCaption: false,
			 showPreview : true, //是否显示预览'
		     language : 'zh',
			 uploadUrl: 'agentwhite/upload',
			 allowedPreviewTypes : [ 'image' ],
		     allowedFileExtensions : [ 'jpg', 'png', 'gif' ],
		     browseClass: "am-btn am-btn-danger am-btn-sm", //按钮样式
		     dropZoneEnabled: false,//是否显示拖拽区域
			 uploadAsync:false,
			 uploadClass:'btn btn-default uploadBtnColor',
			 browseIcon:'<i class="am-icon-cloud-upload"></i>',
			 browseLabel:label,
			 removeIcon: '<i class="am-icon-trash"></i>',
			 layoutTemplates:{'footer':''},
			 initialPreview:initImg,
		}).on("filebatchuploadsuccess", function(event, data) {
		    if(data.response.ret==200){
		    	$('#'+showId+'').val(data.response.data);
		    	$('#coverImg').val(data.response.content.info);
		    	layer.msg('上传成功', {
		    		  icon: 1,
		    		  time: 2000 //2秒关闭（如果不配置，默认是3秒）
		    		}); 
		    } else{
		    	layer.msg('服务器错误，请稍后重试~', {
		    		  icon: 3,
		    		  time: 3000 //2秒关闭（如果不配置，默认是3秒）
		    		}); 
		    }
		}); 
	}
	
	function addItemValue(name){
		$("#"+name+"Div").css("visibility","visible");		
	}
	
	function removeItemValue(name){
		var itemName = $("#"+name+"Name").val();
		var itemId = $("#"+name+"Id").val();
		
		var idx1 = itemName.lastIndexOf(",");
		var idx2 = itemId.lastIndexOf(",");
		if(idx1 == -1){
			$("#"+name+"Name").val("");
			$("#"+name+"Id").val("");
		}else{
			$("#"+name+"Name").val(itemName.substring(0,idx1));
			$("#"+name+"Id").val(itemId.substring(0,idx2));
		}
	}
	
	$('#countySel').chosen().change(function () {
		var selVal = $("#countySel").find("option:selected").val();
		var selText = $("#countySel").find("option:selected").text();
		var countyName = $("#countyName").val();
		var countyId = $("#countyId").val();
		if(selVal){
			if(countyId.length>0){
				$("#countyName").val(countyName+','+selText);
				$("#countyId").val(countyId+','+selVal);
			}else{
				$("#countyName").val(selText);
				$("#countyId").val(selVal);
			}
		}
		$("#countyDiv").css("visibility","hidden");
    });
	$('#townSel').chosen().change(function () {
		var selVal = $("#townSel").find("option:selected").val();
		var selText = $("#townSel").find("option:selected").text();
		var townName = $("#townName").val();
		var townId = $("#townId").val();
		if(selVal){
			if(townId.length>0){
				$("#townName").val(townName+','+selText);
				$("#townId").val(townId+','+selVal);
			}else{
				$("#townName").val(selText);
				$("#townId").val(selVal);
			}
		}
		$("#townDiv").css("visibility","hidden");
    });
		]]>
	</script>